package com.ruoyi.framework.listener;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
@Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {
    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent event) {
        Map<String, Integer> passwordErrorCount = AuthenticationFailureListener.passwordErrorCount;
        Map<String, Date> validityTime = AuthenticationFailureListener.validityTimeMap;
        LoginUser user = (LoginUser) event.getAuthentication().getPrincipal();
        // 登陆成功 清除 密码错误集合
        if(passwordErrorCount.containsKey(user.getUsername())){
            passwordErrorCount.remove(user.getUsername());
        }
        // 登陆成功 清除 限制时间集合
        if(validityTime.containsKey(user.getUsername())){
            validityTime.remove(user.getUsername());
        }
    }
}
